package com.itheima.socket.udp.demo01;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ReceiveDemo01 {

    public static void main(String[] args) throws IOException {

        DatagramSocket datagramSocket = new DatagramSocket(8888);

        byte[] bytes = new byte[1024];
        int length = bytes.length;
        DatagramPacket datagramPacket = new DatagramPacket(bytes, length);

        datagramSocket.receive(datagramPacket);

        byte[] data = datagramPacket.getData();
        int length1 = data.length;
        System.out.println(new String(data, 0, length1));

        datagramSocket.close();

    }

}
